package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级相关接口")
public class NursingLevelController extends BaseController{

    @Autowired
    private NursingLevelService nursingLevelService;


    @GetMapping("/listAll")
    @ApiOperation(value = "查询所有护理等级")
    public ResponseResult selectAll(){
        List<NursingLevelVo> list= nursingLevelService.selectAll();
        return success(list);
    }

    @PostMapping("/insert")
    @ApiOperation(value = "新增护理等级")
    public ResponseResult add(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.add(nursingLevelDto);
        return success();
    }

    @GetMapping("/listByPage")
    @ApiOperation(value = "条件分页查询")
    public ResponseResult sel(@ApiParam(value = "护理等级名称") String name,
                              @ApiParam(value = "护理等级状态") Integer status,
                              @ApiParam(value = "护理等级页码" ) Integer pageNum,
                              @ApiParam(value = "护理等级每页个数") Integer pageSize){
        PageResponse p = nursingLevelService.sel(name,status,pageNum,pageSize);
        return success(p);
    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询")
    public ResponseResult updatesel(@ApiParam(value = "输入查询id") @PathVariable("id") long id ) {
        NursingLevelVo nursingLevelVo=nursingLevelService.updatesel(id);
        return success(nursingLevelVo);
    }

    @PutMapping("/update")
    @ApiOperation(value = "修改护理等级")
    public ResponseResult updata(@RequestBody NursingLevelDto nursingLevelDto){
        nursingLevelService.updata(nursingLevelDto);
        return success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除护理等级")
    public  ResponseResult del(@ApiParam(value = "输入删除id") @PathVariable("id") long id){
        nursingLevelService.del(id);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "护理等级禁用")
    public  ResponseResult stopstatus(@ApiParam(value = "禁用护理等级id") @PathVariable("id") long id,
                                        @PathVariable("status") byte status){
        nursingLevelService.stopstatus(id,status);
        return success();
    }
}
